package guda.house.web.action.bill;

import guda.grape.autogen.common.page.BizResult;
import guda.grape.util.RequestUtil;
import guda.house.biz.BillPayBiz;
import guda.house.biz.form.ReverseForm;
import guda.house.biz.security.AppUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * Created by well on 16/1/7.
 */
@Controller
@RequestMapping(value = "bill/reverse")
public class ReverseAction {

    @Autowired
    private BillPayBiz billPayBiz;

    @RequestMapping(value = "/create.htm")
    public String create(HttpServletRequest request, ModelMap modelMap,ReverseForm reverseForm) {


        BizResult bizResult = billPayBiz.queryForReverse(reverseForm.getPayId());
        modelMap.putAll(bizResult.data);
        return "bill/reverse/create.vm";
    }

    @RequestMapping(value = "/doReverse.htm",method = RequestMethod.POST)
    public String doReverse(HttpServletRequest request, ModelMap modelMap,@Valid ReverseForm reverseForm,BindingResult result) {
       if(result.hasErrors()){
           BizResult bizResult = billPayBiz.queryForReverse(reverseForm.getPayId());
           modelMap.putAll(bizResult.data);
           return "bill/reverse/create.vm";
       }
        BizResult bizResult = billPayBiz.reverse(reverseForm);
        modelMap.putAll(bizResult.data);
        return "bill/reverse/result.vm";
    }
}
